import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
// import { createVuePlugin } from 'vite-plugin-vue';
import path from 'path';
export const resolve = (dir: any): any => {
    const _path = path.resolve(__dirname, dir);
    return _path;
};

// https://vitejs.dev/config/
export default defineConfig({
    server: {
        port: 10100
        // host: true // 监听所有地址
    },
    resolve: {
        alias: {
            '@': resolve('./src'),
            '@assets': resolve('src/assets'),
            '@components': resolve('./src/components'),
            '@views': resolve('./src/views')
        }
    },
    css: {
        preprocessorOptions: {
            less: {
                additionalData: '@import "./src/styles/index.less";',
                javascriptEnabled: true
            }
        }
    },
    plugins: [
        vue()
        // externals({
        //     include: '**/*.ts', // 包含的文件类型，可以根据实际需要调整
        //     exclude: ['**/docs/**'] // 要排除的文件夹
        // })
    ],
    build: {
        target: 'es2015',
        cssTarget: 'chrome80',
        outDir: 'dist',
        assetsDir: 'assets', // 静态资源的存放目录
        reportCompressedSize: false,
        chunkSizeWarningLimit: 2000,
        lib: {
            entry: 'src/index.ts', // 入口文件路径
            name: 'li-cloud-ui', // 组件库名称
            formats: ['es']
        },
        rollupOptions: {
            external: ['vue'], // 如果你的库依赖于 Vue，并且你不想把它打包进你的库里，你可以把它列为外部依赖
            output: {
                globals: {
                    vue: 'Vue'
                },
                //   exports: 'named',
                // 确保你的库可以被默认导入
                exports: 'auto'
            }
        }
    },
    optimizeDeps: {
        // entries: ['src/index.ts'],
        // include: ['li-cloud-ui']
    }
});
